//
//  LX_VisitorView.swift
//  swiftWeiBo
//
//  Created by 轩 on 16/7/18.
//  Copyright © 2016年 KXuan. All rights reserved.
//

import UIKit

///访客视图
class LX_VisitorView: UIView {
    
    ///通过代码创建的，走initWithFrame
    override init(frame: CGRect) {
        super.init(frame: frame)
        self.backgroundColor = UIColor.grayColor()
        
        
        
        setupUI()
        
    }
    
    
    ///使用约束对控件进行布局
    func setupUI() ->Void
    {
        //添加自定义控件
        self.addSubview(cycleImageView)//因为轮环在house的底部，所以需要先添加
        self.addSubview(houseImageView)
        self.addSubview(WelcomeLabel)
        self.addSubview(loginBtn)
        self.addSubview(regisBtn)
        
        
        //关闭autoresizing
        for item in self.subviews
        {
            item.translatesAutoresizingMaskIntoConstraints = false
        }
        
        
        //设置图片
        self.addConstraint(NSLayoutConstraint(item: self.cycleImageView, attribute: NSLayoutAttribute.CenterX, relatedBy: NSLayoutRelation.Equal, toItem: self, attribute: NSLayoutAttribute.CenterX, multiplier: CGFloat(1), constant: CGFloat(0)))
        self.addConstraint(NSLayoutConstraint(item: self.cycleImageView, attribute: NSLayoutAttribute.CenterY, relatedBy: NSLayoutRelation.Equal, toItem: self, attribute: NSLayoutAttribute.CenterY, multiplier: CGFloat(1), constant: CGFloat(0)))
        
        //设置house
        self.addConstraint(NSLayoutConstraint(item: self.houseImageView, attribute: NSLayoutAttribute.CenterX, relatedBy: NSLayoutRelation.Equal, toItem: self, attribute: NSLayoutAttribute.CenterX, multiplier: CGFloat(1), constant: (0)))
        self.addConstraint(NSLayoutConstraint(item: self.houseImageView, attribute: NSLayoutAttribute.CenterY, relatedBy: NSLayoutRelation.Equal, toItem: self, attribute: NSLayoutAttribute.CenterY, multiplier: CGFloat(1), constant: CGFloat(0)))
        
        
        //设置label
        self.addConstraint(NSLayoutConstraint(item: self.WelcomeLabel, attribute: NSLayoutAttribute.CenterX, relatedBy: NSLayoutRelation.Equal, toItem: self, attribute: NSLayoutAttribute.CenterX, multiplier: CGFloat(1), constant: CGFloat(0)))
        
        self.addConstraint(NSLayoutConstraint(item: self.WelcomeLabel, attribute: NSLayoutAttribute.Top , relatedBy: NSLayoutRelation.Equal, toItem: self, attribute: NSLayoutAttribute.CenterY, multiplier: CGFloat(1), constant: CGFloat(40)))
        
        self.addConstraint(NSLayoutConstraint(item: self.WelcomeLabel, attribute: NSLayoutAttribute.Leading, relatedBy: NSLayoutRelation.Equal, toItem: self, attribute: NSLayoutAttribute.Leading, multiplier: CGFloat(1), constant: CGFloat(40)))
        
        self.addConstraint(NSLayoutConstraint(item: self.WelcomeLabel, attribute: NSLayoutAttribute.Trailing, relatedBy: NSLayoutRelation.Equal, toItem: self, attribute: NSLayoutAttribute.Trailing, multiplier: CGFloat(1), constant: CGFloat(40)))
        
        
        
        //设置登录
        //设置注册
        
        
    }
    
    
    //因为重写了initWithFrame，所以父类的构造方法全没了，需要补上
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    ///轮huan
    lazy var cycleImageView : UIImageView = {
        let cycle = UIImageView(image: UIImage(named: "visitordiscover_feed_image_smallicon"))
        return cycle
    }()
    
    ///house
    lazy var houseImageView : UIImageView = {
        let house = UIImageView(image: UIImage(named: "visitordiscover_feed_image_house"))
        return house
    }()
    
    ///label
    lazy var WelcomeLabel:UILabel = {
        let label = UILabel(frame: CGRectZero)
        label.textAlignment = NSTextAlignment.Center
        label.numberOfLines = 0
        label.text = "haijfl;sajfjasjf"
        
        return label
    }()
    
    /// 消息label
    private lazy var messageLabel: UILabel = {
        let label = UILabel(frame: CGRectZero)
        
        // 设置
        label.textAlignment = NSTextAlignment.Center
        label.font = UIFont.systemFontOfSize(15)
        label.textColor = UIColor.darkGrayColor()
        label.numberOfLines = 0
        label.text = "关注一些人,看看有什么惊喜!关注一些人,看看有什么惊喜!关注一些人,看看有什么惊喜!关注一些人,看看有什么惊喜!关注一些人,看看有什么惊喜!"
        // 让控件size根据内容自己调整
        label.sizeToFit()
        
        return label
    }()

    
    
    /// 注册按钮
    private lazy var registerButton: UIButton = {
        let button = UIButton(type: UIButtonType.Custom)
        
        // 设置
        button.setTitle("注册", forState: UIControlState.Normal)
        button.setTitleColor(UIColor.orangeColor(), forState: UIControlState.Normal)
        button.titleLabel?.font = UIFont.systemFontOfSize(18)
        button.setBackgroundImage(UIImage(named: "common_button_white_disable"), forState: UIControlState.Normal)
        
        return button
    }()
    
    /// 登录按钮
    private lazy var loginButton: UIButton = {
        let button = UIButton(type: UIButtonType.Custom)
        
        // 设置
        button.setTitle("登录", forState: UIControlState.Normal)
        button.setTitleColor(UIColor.darkGrayColor(), forState: UIControlState.Normal)
        button.titleLabel?.font = UIFont.systemFontOfSize(18)
        button.setBackgroundImage(UIImage(named: "common_button_white_disable"), forState: UIControlState.Normal)
        
        return button
    }()
    
    
    
    
    lazy var regisBtn :UIButton = {
        let btn = UIButton(type: UIButtonType.Custom)
        
        
        // 设置
        btn.setTitle("注册", forState: UIControlState.Normal)
        btn.setTitleColor(UIColor.orangeColor(), forState: UIControlState.Normal)
        btn.titleLabel?.font = UIFont.systemFontOfSize(18)
        btn.setBackgroundImage(UIImage(named: "common_button_white_disable"), forState: UIControlState.Normal)
        
        
        return btn
    }()

    
    lazy var loginBtn :UIButton = {
        let btn = UIButton(type: UIButtonType.Custom)

    btn.setBackgroundImage(UIImage(named:"common_button_white_disable"), forState: UIControlState.Normal)
        btn.setTitle("登录", forState: UIControlState.Normal)
        btn.titleLabel?.font = UIFont.systemFontOfSize(18)
        btn.setTitleColor(UIColor.darkGrayColor(), forState: UIControlState.Normal)
        
        return btn
    }()
    
    
    
}
